<template>
  <main>
    <section class="clean-block clean-form dark" style="background: rgb(255,255,255);">
      <div class="container">
        <div class="block-heading">
          <h2 class="text-info">登录</h2>
          <p>如果你是商家，请点击<el-button type="text" @click="toVentor()">这里</el-button></p>
        </div>
        <form>
          <div class="mb-3"><label class="form-label"><span class="bi-phone"> 手机号</span></label><input class="form-control" type="text" v-model="user.utelephone"></div>
          <div class="mb-3"><label class="form-label"><span class="bi-123"> 密码</span></label><input class="form-control" type="text" v-model="user.upassword"></div>
          <div class="mb-3"><el-button type="primary" @click="login()">登录</el-button></div>
        </form>
      </div>
    </section>
  </main>
</template>

<script>
import axios from "axios";

export default {
  name: "Login",
  data(){
    return{
      //users:[],
      // utelephone:'',
      // utelephone:'',
      user:{
        utelephone:'',
        upassword:''
      }
    }
  },
  methods:{
    login(){
      if (this.user.utelephone ==='' || this.user.upassword ===''){
        this.$message.error("用户名或密码不能为空");
      } else {
        axios.post('http://r44734h518.zicp.vip:41569/user/selectUser',this.user).then(res=>{
          if (res.data !== null) {
            sessionStorage.setItem("isLogin","true");
            sessionStorage.setItem("uname",res.data.uname);
            sessionStorage.setItem("uid",res.data.uid);
            sessionStorage.setItem("utelephone",res.data.utelephone);
            sessionStorage.setItem("upassword",res.data.upassword);
            this.$emit('login');
            this.$router.push({path:'/'});
            this.$notify.success("欢迎回来,"+sessionStorage.getItem("uname")+"!");
          } else {
            this.$message.error("账号或密码错误");
          }
        }).catch(error=>{
          this.$message.error("网络连接错误");
        })
      }
    },
    toVentor(){
      window.open("http://10.37.129.2:8081/#/login");
    }
  },
  beforeCreate() {
    if (sessionStorage.getItem("isLogin")){
      this.$message.warning("你已登录");
      this.$router.push({path:'/infos'});
    }
  },
  created() {
  }
}
</script>

<style scoped>

</style>
